# coding:utf-8
import datetime

from django.db import models

# Create your models here.


class User(models.Model):
    user = models.CharField(max_length=20, verbose_name='用户', null=False)
    add_time = models.DateTimeField(verbose_name="最后登入时间", auto_now=True)
    last_use_time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True)
    use_number = models.IntegerField(verbose_name="登入次数", default=0)

    class Meta:
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user


class SubjectCategory(models.Model):
    user = models.ForeignKey(User, verbose_name="用户", on_delete=models.CASCADE, default=1)
    subject = models.CharField(max_length=20, verbose_name='学科类别', null=False)

    class Meta:
        verbose_name = '类别所属表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.subject


class Category(models.Model):
    user = models.ForeignKey(User, verbose_name="用户", on_delete=models.CASCADE, default=1)
    subject_category = models.ForeignKey(SubjectCategory, verbose_name="科目种类", on_delete=models.CASCADE, default=6)
    category = models.CharField(max_length=20, verbose_name='种类', null=False)
    add_time = models.DateTimeField(verbose_name="最后使用时间", auto_now=True)
    last_use_time = models.DateTimeField(verbose_name="添加时间", auto_now_add=True)
    use_number = models.IntegerField(verbose_name="使用次数", default=0)

    class Meta:
        verbose_name = '用户信息表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category


class UseTime(models.Model):
    user = models.ForeignKey(User, verbose_name="用户", on_delete=models.CASCADE, default=1)
    category = models.ForeignKey(Category, verbose_name="种类", on_delete=models.CASCADE)
    start_time = models.DateTimeField(verbose_name="开始时间")
    stop_time = models.DateTimeField(verbose_name="结束时间")
    use_time = models.FloatField(verbose_name="用时", default=0)

    class Meta:
        verbose_name = "各类花费的时间表"
        verbose_name_plural = verbose_name
